﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Share/Index.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<% 
    IList list = (IList)ViewData["sectionlist"];
%>
<script language="JavaScript">
    var UserClass = { uic_id: 0, uic_class: "", uic_teacher: "", uic_state: 1, uic_date: new Date() };
    var mylist;
    var regular_input = {
        uic_class: { exp: /^.{1,25}$/, m: "请输入班级名，25个字符以内" }
    }
    var mainForm = "";
    $(document).ready(function () {
        //mainForm = $("#mainForm").html();
        mylist = new TurnPage("mylist");
        mylist.pageSize = 8;
        mylist.callback = function () { ajax(); };

        function ajax() {
            var classname = $.trim($("#seekForm :input[name=txtclassName]").val());
            var teacher = $.trim($("#seekForm :input[name=txtteacher]").val());
            var in_s = $.trim($("#seekForm :input[name=txtin_s]").val());
            var in_e = $.trim($("#seekForm :input[name=txtin_e]").val());
            var param = { pagesize: mylist.pageSize, pageno: mylist.currPage, classname: classname, teacher: teacher, in_s: in_s, in_e: in_e };
            $.post("/LibraryBook/getUserClasslist.html?" + (new Date()).getTime(), param, function (data) {
                data = $.evalJSON(data);
                if (mylist.currPage == 1) {
                    mylist.total = $.grep(data, function (n, i) { return typeof (n.total) == "number"; })[0].total - 1; //这里因为默认班级不显示，所以-1
                    data = $.grep(data, function (n, i) { return typeof (n.total) == "undefined"; });
                }
                loadDta(data);
            });
        }

        var loadDta = function (list) {
            var sp = [];
            var mapid;
            $("#mainTable tbody[name=mainlist]").html("");
            $.each(list, function (i, n) {
                if (n.uic_class != '默认班级') {
                    sp.push('<tr>');
                    sp.push('<td>' + n.uic_class + '</td>');
                    sp.push('<td>' + n.ct + '</td>');
                    sp.push(n.uic_class == '默认班级' ? '<td></td>' : '<td><a href="#mainForm" onclick="edit(' + n.uic_id + ')" name="linkEdit" vid="' + n.uic_id + '">修改</a>  <a href="#" onclick="del(' + n.uic_id + ')" name="linkDel" >删除</a></td>');
                    sp.push('</tr>');
                }
            });
            $("#mainTable tbody[name=mainlist]").append(sp.join(''));
            //if (sp.length == 0) alert('没有符合条件的数据');
            $("#pager").html(mylist.getOutput());
        }
        $("input[name=buttSeek]").click(function () {
            mylist.currPage = 1;
            ajax();
        });
        ajax();
        $("input[name=buttReset]").click(function () {
            $("input[name=uic_class]").val('');
            $("input[name=uic_teacher]").val('');
        });
        $("input[name=buttsend]").click(function () {
            if (!$.checkFormValid("mainForm")) return false;
            $.fillObj(UserClass, "#mainForm");
            $.post("/LibraryBook/checkClassName.html", { className: $("#uic_class").val(), id: UserClass.uic_id }, function (d) {
                if (d == "0") {
                    $.post("/LibraryBook/saveUserClass.html", { UserClass: $.toJSON(UserClass) }, function (dta) {
                        alert("保存成功");
                        window.parent.frames["rightFrame"].location.reload();
                        ajax();
                    });
                }
                else {
                    alert("班级名重复");
                }
            });
        });
    })
    function edit(id) {
        $.post("/LibraryBook/getUserClassbyid.html?" + (new Date()).getTime(), { res: id }, function (dta) {
            UserClass = $.evalJSON(dta);
            $.fillForm(UserClass, "#mainForm");
        });
        $("input[name=buttsend]").val('修改');
    }
    function del(id) {
        if (confirm("是否确定")) {
            $.post("/LibraryBook/deleteUserClass.html?" + (new Date()).getTime(), { res: id }, function (dta) {
                location.reload();
            });
        }
    }
</script>
    <table cellspacing="0" id="seekForm">
        <tr>
            <th>
                班级管理
            </th>
        </tr>
        <tr>
        <td>
        班级名：<input type="text" name="txtclassName" />
        班主任：<input type="text" name="txtteacher" />
         添加日期：<input type="text" size="15" name="txtin_s" value="<%=System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd") %>" class="date" />
                至<input type="text" size="15" name="txtin_e" value="<%=System.DateTime.Now.ToString("yyyy-MM-dd") %>" class="date" />
                <script type="text/javascript">
                    $(document).ready(function () {
                        $(function () {
                            $(':text[name=txtin_s]').datepicker({
                                numberOfMonths: 1,
                                showButtonPanel: true,
                                changeMonth: true,
                                yearRange: '-40:+1', changeYear: true
                            });
                            $(':text[name=txtin_e]').datepicker({
                                numberOfMonths: 1,
                                showButtonPanel: true,
                                changeMonth: true,
                                yearRange: '-40:+1', changeYear: true
                            });
                        });
                    });
                </script>
                <input type="button" name="buttSeek" value="查询" onclick="" class="btn1" />
        </td>
        </tr>
    </table>
    <table id="mainTable" cellspacing="0">
        <caption style="color: red; font-size: 15px; font-weight: bold">管理员列表</caption>
        <tr>
            <th>
                班级名
            </th>
            <th>
                班主任
            </th>
            <th>
            </th>
        <tbody name="mainlist">
        
        </tbody>
    </table>
    <div id="pager" class="pager">
    </div>
    <table cellspacing="0" id="mainForm">
        <tr>
            <th colspan="3">
                编辑班级
            </th>
        </tr>        
       <tr>
            <td>班级名*</td>
            <td><input id="uic_class" name="uic_class" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
         <tr>
            <td>班主任</td>
            <td><input id="uic_teacher" name="uic_teacher" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
        <tr class="main-status" id="mainstatus" style="display: none">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                正在验证表单....
            </td>
        </tr>
        <tr class="main-sub" id="mainsub">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                <input type="button" name="buttsend" class="btn1" style="width: 200px" 
                    value="新增" />
                <input type="button" name="buttReset" class="btn1" style="width: 200px" value="重置" />
            </td>
        </tr>
    </table>
</asp:Content>
